
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import '../app/routes/app_pages.dart';

// 使用方法
// 1.使用obs变量：XXXController : --> var dateOne = '选择日期'.obs;
// 2.Obx(() => MyDatePicker(value: controller.dateOne.value, valueChanged: (String value) { print(value); controller.dateOne.value = value;},)),



class MyDatePicker extends StatefulWidget {
  // 传入参数
  const MyDatePicker({
    Key? key,
    required this.valueChanged,
    this.value = '选择日期',
    this.width = 280,
  }) : super(key: key,);

  final ValueChanged<String> valueChanged;
  final String value;
  final double width;

  @override
  State<StatefulWidget> createState() => MyDatePickerState();

}
// var dateStr = '选择日期'.obs;

class MyDatePickerState extends State<MyDatePicker> {

  // void datePicker() async {
  //   await Get.toNamed(Routes.DATEPICKER)?.then((value) async {
  //     if (value == null) return;
  //     if (value == '') return;
  //     widget.valueChanged(value);
  //   });
  // }
  void clean() {
    widget.valueChanged('选择日期');
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
            padding: EdgeInsets.fromLTRB(12, 0, 12, 0),
            margin: EdgeInsets.all(0),
            width: widget.value== '选择日期'?120:widget.width,
            // decoration: BoxDecoration(
            //   border: Border.all(
            //     width: 1,
            //     color: Colors.blueGrey,
            //   ),
            //   borderRadius: BorderRadius.circular(10),
            // ),
            child:Row(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              // crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                TextButton(
                  // style: ButtonStyle(
                  //   minimumSize: MaterialStateProperty.all(Size(1, 1)),
                  //   padding: MaterialStateProperty.all(EdgeInsets.zero),
                  //   // backgroundColor: MaterialStateProperty.all(Colors.grey),
                  // ),
                  //   onPressed: (){datePicker(); },
                    onPressed: (){ },
                    child:  widget.value== '选择日期'?Text(widget.value,style: TextStyle(fontSize: 16.0,color: Colors.black54),):Text(widget.value,style: TextStyle(fontSize: 16.0,),)
                ),
                widget.value== '选择日期'?SizedBox():IconButton(
                  icon: Icon(Icons.cancel_outlined,color: Colors.black12,),
                  iconSize: 20,
                  onPressed: (){clean();},
                ),
              ],
            )
        ),
        Divider(
          height: 0.2,
          indent: 0.0,
          color: Colors.black38,
        ),
      ],
    );

  }

}